import functools
import math
import random

class Conf:
    TRAFFIC_START_TIME = 200
    FLOW_ATTRIBUTES = ['sip', 'sp', 'dip', 'dp'] # see /MySSFNet/ssfnet_src/SSF/OS/DumpPro.java
    MAX_NEIGHBOURS = 30
    NUMBER_OF_FLOWS = 5000
    MAX_CLIENTS = 2**7
    DECREASE_FACTOR = 6
    TIER_1_THRESHOLD = 14
    TIER_1_BORDER_TTL_PENALTY_DISTRIBUTION = random.paretovariate
    TIER_1_BORDER_TTL_PENALTY_DISTRIBUTION_ARGUMENTS = ((2.5,))
    NON_TIER_1_BORDER_TTL_PENALTY_DISTRIBUTION = random.normalvariate
    NON_TIER_1_BORDER_TTL_PENALTY_DISTRIBUTION_ARGUMENTS = ((3, 1.5, ))
    
    def numberOfPrefixesAndTTLPenalty(self, prefixes):
        numberOfPrefixes = functools.reduce(lambda x,y : x + y.num_addresses, prefixes, 0) / 2**8
        if numberOfPrefixes < 2**8:
            ttl_penalty = int((math.log2(2**8))/2)
        else:
            ttl_penalty = int((math.log2(numberOfPrefixes))/2)
        if numberOfPrefixes > 2**16:
            return self.MAX_CLIENTS, ttl_penalty
        if numberOfPrefixes > 2**14:
            return self.MAX_CLIENTS - 4 * self.DECREASE_FACTOR, ttl_penalty
        if numberOfPrefixes > 2**12:
            return self.MAX_CLIENTS - 8 * self.DECREASE_FACTOR, ttl_penalty
        if numberOfPrefixes > 2**10:
            return self.MAX_CLIENTS - 16 * self.DECREASE_FACTOR, ttl_penalty
        if numberOfPrefixes > 2**8:
            return self.MAX_CLIENTS - 18 * self.DECREASE_FACTOR, ttl_penalty
        if numberOfPrefixes > 2**6:
            return self.MAX_CLIENTS - 20 * self.DECREASE_FACTOR, ttl_penalty
        return 1, ttl_penalty
